package com.itheima.hmshopping.app.controller;

import com.itheima.hmshopping.app.service.SmsHomeNewProductService;
import com.itheima.hmshopping.entity.SmsHomeNewProduct;
import com.itheima.hmshopping.util.HmPage;
import com.itheima.hmshopping.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController {

    @Autowired
    private SmsHomeNewProductService smsHomeNewProductService;


    //添加首页新品
    @PostMapping("create")
    public R create(@RequestBody SmsHomeNewProduct smsHomeNewProduct){
        smsHomeNewProductService.create(smsHomeNewProduct);
        return R.succeed("","ok");
    }

    //批量删除首页新品
    @PostMapping("delete")
    public R delete(@RequestParam("ids") List<Long> ids){
        smsHomeNewProductService.delete(ids);
        return R.succeed("","ok");
    }

    //分页查询首页新品
    @GetMapping("list")
    public R list(@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize,
                  String productName,Integer recommendStatus){
       HmPage hmPage= smsHomeNewProductService.page(pageNum,pageSize,productName,recommendStatus);
       return R.succeed(hmPage,"ok");
    }

    //批量修改首页新品状态
    @PostMapping("update/recommendStatus")
    public R recommendStatus(@RequestParam("ids") List<Long> ids,Integer recommendStatus){
        smsHomeNewProductService.recommendStatus(ids,recommendStatus);
        return R.succeed("","ok");
    }

    //修改首页新品排序
    @PostMapping("update/sort/{id}")
    public R sort(@PathVariable Long id,Integer sort){
        smsHomeNewProductService.sort(id,sort);
        return R.succeed("","ok");
    }
}
